package com.ruoyi.project.system.service.impl;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.project.system.domain.SysAttr;
import com.ruoyi.project.system.domain.SysPost;
import com.ruoyi.project.system.mapper.SysAttrMapper;
import com.ruoyi.project.system.mapper.SysPostMapper;
import com.ruoyi.project.system.service.ISysAttrService;
import com.ruoyi.project.system.service.ISysPostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 属性信息 服务层处理
 * 
 * @author ruoyi
 */
@Service
public class SysAttrServiceImpl implements ISysAttrService
{
    @Autowired
    private SysAttrMapper attrMapper;


    @Override
    public List<SysAttr> selectAttrList(SysAttr attr) {
        return attrMapper.selectAttrList(attr);
    }

    @Override
    public SysAttr selectAttrById(Long attrId) {
        return attrMapper.selectAttrById(attrId);
    }

    @Override
    public String checkAttrNameUnique(SysAttr attr) {
        Long postId = StringUtils.isNull(attr.getAttrId()) ? -1L : attr.getAttrId();
        SysAttr info = attrMapper.checkAttrNameUnique(attr.getName());
        if (StringUtils.isNotNull(info) && info.getAttrId().longValue() != postId.longValue())
        {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }

    @Override
    public int deleteAttrById(Long attrId) {
        return attrMapper.deleteAttrById(attrId);
    }

    @Override
    public int insertAttr(SysAttr attr) {
        return attrMapper.insertAttr(attr);
    }

    @Override
    public int updateAttr(SysAttr attr) {
        return attrMapper.updateAttr(attr);
    }

    @Override
    public List<Integer> selectAttrListByDeptId(Long deptId) {
        return attrMapper.selectAttrListByDeptId(deptId);
    }
}
